# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from fastapi import APIRouter, Request, Depends
from hypertext import R, response_json, PagingResult
from apps.api.schemas.agent.know import manage_schema as schema
from apps.api.service.agent.know.manage_service import KnowManageService

router = APIRouter(prefix="/manage", tags=["知识库管理接口"])


@router.get("/whole", summary="全部知识库", response_model=R[PagingResult[schema.KnowWholeVo]])
@response_json
async def whole(request: Request, params: schema.KnowWholeIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await KnowManageService.whole(user_id, params)


@router.get("/lists", summary="知识库列表", response_model=R[PagingResult[schema.KnowListVo]])
@response_json
async def lists(request: Request, params: schema.KnowSearchIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await KnowManageService.lists(params, user_id)


@router.get("/detail", summary="知识库详情", response_model=R[schema.KnowDetailVo])
@response_json
async def detail(request: Request, params: schema.KnowDetailIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await KnowManageService.detail(params.code, user_id)


@router.post("/add", summary="知识库创建", response_model=R)
@response_json
async def add(request: Request, params: schema.KnowAddIn):
    user_id: int = int(request.state.user_id)
    return await KnowManageService.add(params, user_id)


@router.post("/edit", summary="知识库编辑", response_model=R)
@response_json
async def edit(request: Request, params: schema.KnowEditIn):
    user_id: int = int(request.state.user_id)
    return await KnowManageService.edit(params, user_id)


@router.post("/delete", summary="知识库删除", response_model=R)
@response_json
async def delete(request: Request, params: schema.KnowDeleteIn):
    user_id: int = int(request.state.user_id)
    return await KnowManageService.delete(params.code, user_id)


@router.post("/change_vector", summary="变更向量模型", response_model=R)
@response_json
async def change_vector(request: Request, params: schema.KnowChangeVectorIn):
    user_id: int = int(request.state.user_id)
    return await KnowManageService.change_vector(params.code, user_id, params.vector_model)
